package frame.base;

import java.util.Objects;
import java.util.TreeSet;

public class ZTree implements Comparable<ZTree>{
    private Integer id;
    private Integer pid;
    private String name;
    private String icon;
    private Integer sorting;
    private Object data;
    private TreeSet<ZTree> children = new TreeSet<>();

    public Integer getId() {
        return id;
    }

    public ZTree setId(Integer id) {
        this.id = id;
        return this;
    }

    public Integer getPid() {
        return pid;
    }

    public ZTree setPid(Integer pid) {
        this.pid = pid;
        return this;
    }

    public String getName() {
        return name;
    }

    public ZTree setName(String name) {
        this.name = name;
        return this;
    }

    public String getIcon() {
        return icon;
    }

    public ZTree setIcon(String icon) {
        this.icon = icon;
        return this;
    }

    public Integer getSorting() {
        return sorting;
    }

    public ZTree setSorting(Integer sorting) {
        this.sorting = sorting;
        return this;
    }

    public Object getData() {
        return data;
    }

    public ZTree setData(Object data) {
        this.data = data;
        return this;
    }

    public TreeSet<ZTree> getChildren() {
        return children;
    }

    public ZTree addChildren(ZTree child) {
        this.children.add(child);
        return this;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ZTree tree = (ZTree) o;
        return id.equals(tree.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

    @Override
    public int compareTo(ZTree o) {
        if (o == null) return 0;
        return this.sorting.compareTo(o.sorting);
    }
}
